import { message } from 'ant-design-vue'
import { URL_PRIX, Messages, WEB_ROOT_PATH } from '@Config/config'
import { options } from 'numeral'
import NetWork from '@Config/server/api/base'
import JSEncrypt from 'jsencrypt'
//登录接口
export const Login = async (_data) => {
  // return {
  //   code: 0,
  //   msg: 'success',
  //   data: {
  //     userId: 42006,
  //     token: '21f30cc814fc4ef7bd6845ce9a35a19e',
  //     userName: 'zhengqiangzi',
  //     nickname: '郑强子',
  //     adminFlag: 1,
  //     roleNameList: ['超管'],
  //     permissionTagList: ['first', 'second'],
  //   },
  // }
  let _encrypt = new JSEncrypt()
  _encrypt.setPublicKey(
    'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCVhxd4+rxvar/uL58KYEuRPzU7eZbZJQmkqRCq36DlkTibRUvDsUNxwnZRdb/GlcR5bii32bXH1IIxFWMhrZl0EHSjIB3LTWo56Ki+TTeXp4UkEfTb5iRAe2IkWhYwUisv4ABkHFgzCfMGUW1vFv3mFb09ojJkntyUsNlZQWvtZwIDAQAB'
  )
  let encrypt_result = _encrypt.encrypt(_data.pass)
  _data.pass = encrypt_result

  // console.log(_data.pass)
  // var decrypt = new JSEncrypt() //创建解密对象实例
  // //之前ssl生成的秘钥
  // var priKey =
  //   'MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAJ0eC1RyKbIcafsU1fc6YMNEXt9f/ZZSfhnpKGVHbPbw+fHX0PzAEMXXYbIsP5gncIw1PdEceIR07XVpqJn97D2vEX82iXvqBagdX1GCloukGMM+nAzYGPMnwdQH8sGkqaWoxQMbJYKhhVmS76g+KSoD1bOl0tvP9HS/+7LcKOpfAgMBAAECgYAbJeHXSZKiz/4QAF2oRlIJ63ppJnDu1Hoth/gO5/SQBrtpal0WDynWxYx/+N1UMRxlXZ280CqS2JFfRE55rUJwb6cT28L+NnRjw57B4LW7hEeUxxFlHYERPr05CMjb0oL3s3DjqGtODsfTSAQAYimV/GU3D92WT0feITI1rVA7wQJBAPCEvZI9J9JvW/hL4TqwLi6jID4YC7bmgz8JhWRaNknou9smlffo6Da40ltTKYY5K/aMuhgMBNiloKSbRC50TrcCQQCnOwVl7eCsjXnPeX9NyVUvN8KuoTVUyB9u28KFh/t/rOD6L6xRG1w/FHY4cP2KC9c2uAgtumboKEZK7w/UuhmZAkEA3u2p6AnXBy1ASXvLXuI9a+y2zdbrxLMTozHn+YPEHe0hcZbqGcY+tbnI/+ys6EPFg9gcBH3fYA7kPq3LHGOhMQJAfG0DtTVq57hUG7TwrXXRtdItPjWgMra7/IXyk9v7mqGMu1nhQm+zERQuagxX+PCabpI7M5rvmmjs9DAvfT4CcQJBALY59I/0yMjI0gQRxJsR75Ph8ZYNqWWcrLU3EeIs1qDdMgVXkbFs2hbFfqyRhmkb3wo7BSLjVHsphJLtVHTmedI='
  // decrypt.setPrivateKey(priKey) //设置秘钥
  // var uncrypted = decrypt.decrypt(_data.pass) //解密之前拿公钥加密的内容

  // console.log(uncrypted)

  let work = await NetWork('/admin/login', {
    body: JSON.stringify(_data),
  })
  work.data.permissionTagList?.push('recycleBinList1')
  work.data.permissionTagList?.push('recycleBinList2')
  // delete work.data.
  // delete work.data.roleNameList
  // delete work.data.isSub
  // console.log(work)
  return work
}
//登出接口
export const LogOut = async () => {
  let work = await NetWork('/admin/loginout', {})
  return work
}

//子账号分页查询

export const adminSubList = async (_data) => {
  let work = await NetWork('/admin/sub/list', {
    body: JSON.stringify(_data),
  })
  return work
}
//（开发中）子账号注册
export const adminSubRegister = async (_data) => {
  let work = await NetWork('/admin/sub/register', {
    body: JSON.stringify(_data),
  })
  return work
}
///admin/sub/register

////admin/sub/modify
export const adminSubModify = async (_data) => {
  let work = await NetWork('/admin/sub/modify', {
    body: JSON.stringify(_data),
  })
  return work
}

//子账号重置密码
export const adminSubReset = async (_data) => {
  let work = await NetWork('/admin/sub/reset', {
    body: JSON.stringify(_data),
  })
  return work
}
//子账号修改状态
export const adminSubEnable = async (_data) => {
  let work = await NetWork('/admin/sub/enable', {
    body: JSON.stringify(_data),
  })
  return work
}

export default NetWork
